
package com.rt.schedulenew.utils.util;
import java.lang.reflect.Method;
import java.beans.PropertyDescriptor;
import java.beans.BeanInfo;
import java.lang.reflect.InvocationTargetException;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.util.LinkedHashMap;
import java.util.Map;
public class BeanUtil
{
    public static Map<String, Object> bean2Map(final Object bean) {
        final Map<String, Object> map = new LinkedHashMap<String, Object>();
        if (bean == null) {
            return map;
        }
        try {
            final BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
            final PropertyDescriptor[] propertyDescriptors2;
            final PropertyDescriptor[] propertyDescriptors = propertyDescriptors2 = beanInfo.getPropertyDescriptors();
            for (final PropertyDescriptor property : propertyDescriptors2) {
                final String key = property.getName();
                if (!key.equals("class")) {
                    final Method getter = property.getReadMethod();
                    final Object value = getter.invoke(bean, new Object[0]);
                    if (value != null) {
                        map.put(key, value);
                    }
                }
            }
        }
        catch (IntrospectionException e) {
            e.printStackTrace();
        }
        catch (IllegalArgumentException e2) {
            e2.printStackTrace();
        }
        catch (IllegalAccessException e3) {
            e3.printStackTrace();
        }
        catch (InvocationTargetException e4) {
            e4.printStackTrace();
        }
        return map;
    }
}
